package com.ava.avamedia.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.ava.avamedia.R;
import com.ava.avamedia.model.Icon;


public class IconAdapter extends BaseAdapter {
	
	private static final String TAG = IconAdapter.class.getSimpleName();
	public ArrayList<Icon> listIcon ;
	public Context ctx;
	LayoutInflater mInflater;
	public IconAdapter(ArrayList<Icon> listIcon, Context ctx) {
		super();
		this.listIcon = listIcon;
		this.ctx = ctx;
		mInflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	public int getCount() {
		// TODO Auto-generated method stub
		return listIcon.size();
	}

	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return listIcon.get(arg0);
	}

	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		HolderIcon holder ;
		if (convertView == null) {
			holder = new HolderIcon();
			convertView = mInflater.inflate(R.layout.adapter_list_icon, null);
			holder.icon = (ImageView) convertView.findViewById(R.id.adapter_list_icon_image_view);
			holder.name= (TextView) convertView.findViewById(R.id.adapter_list_icon_txt_name);
			convertView.setTag(holder);
		}else{
			holder = (HolderIcon) convertView.getTag();
		}
		Icon icon =(Icon) getItem(position);
		Log.i(TAG, "-------->" + icon.imageResource);
		holder.icon.setImageResource(icon.imageResource);
		holder.name.setText(icon.name);
		return convertView;
	}
	class HolderIcon{
		ImageView icon;
		TextView name;
	}
}
